package com.ims.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ims.common.annotation.Log;
import com.ims.common.core.controller.BaseController;
import com.ims.common.core.domain.AjaxResult;
import com.ims.common.enums.BusinessType;
import com.ims.system.domain.TSysSite;
import com.ims.system.service.ITSysSiteService;
import com.ims.common.utils.poi.ExcelUtil;
import com.ims.common.core.page.TableDataInfo;

/**
 * 公司Controller
 *
 * @author IMS
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/system/site")
public class TSysSiteController extends BaseController
{
    @Autowired
    private ITSysSiteService tSysSiteService;

    /**
     * 查询公司列表
     */
    @PreAuthorize("@ss.hasPermi('system:site:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSysSite tSysSite)
    {
        startPage();
        List<TSysSite> list = tSysSiteService.selectTSysSiteList(tSysSite);
        return getDataTable(list);
    }

    /**
     * 导出公司列表
     */
    @PreAuthorize("@ss.hasPermi('system:site:export')")
    @Log(title = "公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSysSite tSysSite)
    {
        List<TSysSite> list = tSysSiteService.selectTSysSiteList(tSysSite);
        ExcelUtil<TSysSite> util = new ExcelUtil<TSysSite>(TSysSite.class);
        util.exportExcel(response, list, "公司数据");
    }

    /**
     * 获取公司详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:site:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSysSiteService.selectTSysSiteById(id));
    }

    /**
     * 获取公司详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:site:query')")
    @GetMapping(value = "/currentSite")
    public AjaxResult getCurrentSite()
    {
        return success(tSysSiteService.getCurrentSite());
    }

    /**
     * 新增公司
     */
    @PreAuthorize("@ss.hasPermi('system:site:add')")
    @Log(title = "公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSysSite tSysSite)
    {
        return toAjax(tSysSiteService.insertTSysSite(tSysSite));
    }

    /**
     * 修改公司
     */
    @PreAuthorize("@ss.hasPermi('system:site:edit')")
    @Log(title = "公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSysSite tSysSite)
    {
        return toAjax(tSysSiteService.updateTSysSite(tSysSite));
    }

    /**
     * 删除公司
     */
    @PreAuthorize("@ss.hasPermi('system:site:remove')")
    @Log(title = "公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSysSiteService.deleteTSysSiteByIds(ids));
    }
}
